package com.mec.web.y2012.coreservlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

@WebServlet("/LongServlet")
public class LongServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public LongServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html");
		//response.setCharacterEncoding("GBK");
		PrintWriter out;
		if(GzipUtilities.isGzipSupported(request) && 
			!GzipUtilities.isGzipDisabled(request)	
				){
			out = GzipUtilities.getGzipWriter(response);
			//Still, here's bad encoding~;
			logger.info("--> use gzip-writer");
		}else{
			out = response.getWriter();
			logger.info("--> use normal request.writer");
		}
		
		//
		String title = "Long Page";
		out.println(Constants.docType + ServletUtilities.headWithTitle(title) +
				"<body><h1>" + title + "</h1>"
					);
		String line = "<p>Long Content here~;</p>";
		out.println( line + "</body></html>");
		
		
		//Needed for gzip, optional otherwise;
		out.close();
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
	
	private static final Logger logger = 
			Logger.getLogger(LongServlet.class);

}
